package com.code.util;
import com.code.entity.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice // 利用AOP对所有的Controller进行增强
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)// 捕获所有异常
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();// 打印异常信息
        System.out.println("调用了公共异常处理模块！");
        return new Result(e.getMessage(),1);
    }

}
